﻿<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
  >
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/SqlMiM.Common;component/Resources/ControlsTheme.xaml"/>
    </ResourceDictionary.MergedDictionaries>


    <!--
  *****************************************************************************
  STYLES AND TEMPLATES
  *****************************************************************************
  -->


    <Style x:Key="Style_HeaderGripper" TargetType="{x:Type Thumb}">
        <Setter Property="Width" Value="1"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Cursor" Value="SizeWE"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    
    <Style TargetType="{x:Type dg:DataGridColumnHeader}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="MinWidth" Value="0" />
        <Setter Property="MinHeight" Value="15" />
        <Setter Property="Foreground" Value="{DynamicResource Foreground}" />
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="FontWeight" Value="Bold"/>
        <!--<Setter Property="FontSize" Value="13.333"/>-->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dg:DataGridColumnHeader}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        
                        <Border x:Name="BackgroundBorder" BorderThickness="1" Margin="0,3,0,0"  Background="Transparent" 
                                BorderBrush="{DynamicResource BrushVeryDark}" Grid.ColumnSpan="2" />
                        <ContentPresenter Margin="6,3,6,3" VerticalAlignment="Center" />
                        <Path x:Name="SortArrow" Visibility="Collapsed" Data="M0,0 L1,0 0.5,1 z" Stretch="Fill" 
                              Grid.Column="1" Width="8" Height="6" Fill="{TemplateBinding Foreground}" 
                              Margin="0,0,8,0" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.4" />
                        <!--<Rectangle Width="1" Fill="{DynamicResource BrushVeryDark}" HorizontalAlignment="Right" Grid.ColumnSpan="2" />
                        <Rectangle Width="1" Margin="0,0,1,0" Fill="{DynamicResource BrushVeryDark}" HorizontalAlignment="Right" Grid.ColumnSpan="2" />-->
                        <Thumb x:Name="PART_LeftHeaderGripper" HorizontalAlignment="Left" Style="{DynamicResource Style_HeaderGripper}"/>
                        <Thumb x:Name="PART_RightHeaderGripper" HorizontalAlignment="Right" Style="{DynamicResource Style_HeaderGripper}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="SortDirection" Value="{x:Null}">
                            <Setter TargetName="BackgroundBorder" Property="BorderBrush"  Value="Transparent" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="BackgroundBorder" Property="BorderBrush" Value="{DynamicResource BrushDark}" />
                        </Trigger>
                        <Trigger Property="SortDirection" Value="Ascending">
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                            <Setter TargetName="SortArrow" Property="RenderTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="180" />
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="SortDirection" Value="Descending">
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                        </Trigger>
                        <Trigger Property="DisplayIndex" Value="0">
                            <Setter Property="Visibility" Value="Collapsed" TargetName="PART_LeftHeaderGripper"></Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- DataGridRowHeader -->

    <Style x:Key="{x:Type dg:DataGridRowHeader}" TargetType="{x:Type dg:DataGridRowHeader}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dg:DataGridRowHeader}">
                    <Border Background="Transparent" Margin="3,0,3,0">
                        <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- DataGridCell -->

    <Style TargetType="{x:Type dg:DataGridCell}">
        <Setter Property="Foreground" Value="{DynamicResource Foreground}" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dg:DataGridCell}">
                    <Border x:Name="BackgroundBorder" Background="Transparent">
                        <ContentPresenter VerticalAlignment="Center" Margin="4,0,6,0" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- DataGridRow -->

    <Style x:Key="{x:Type dg:DataGridRow}" TargetType="{x:Type dg:DataGridRow}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dg:DataGridRow}">
                    <Border x:Name="DGR_Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"  BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True">
                        <dg:SelectiveScrollingGrid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <dg:DataGridCellsPresenter  Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            <dg:DataGridRowHeader dg:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"  Grid.RowSpan="2" Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=HeadersVisibility, Converter={x:Static dg:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static dg:DataGridHeadersVisibility.Row}}"/>
                            <dg:DataGridDetailsPresenter Grid.Column="1" Grid.Row="1" Visibility="{TemplateBinding DetailsVisibility}" />
                        </dg:SelectiveScrollingGrid>
                    </Border>
                    <ControlTemplate.Triggers>

                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="DGR_Border" Property="Background" Value="{DynamicResource BrushMedium}" />
                            <Setter TargetName="DGR_Border" Property="TextElement.Foreground" Value="{DynamicResource BrushDarkness}" />

                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- DataGrid -->


    <Style TargetType="{x:Type dg:DataGrid}" x:Key="SqlMiM.DataGrid" >

        <Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource BrushLight}" />
        <Setter Property="VerticalGridLinesBrush" Value="{DynamicResource BrushLight}" />
        <Setter Property="RowBackground" Value="{DynamicResource BrushOffWhite}" />
        <Setter Property="Foreground" Value="{DynamicResource Foreground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource BrushVeryDark}" />
        <Setter Property="Background" Value="{DynamicResource ColorOffWhite}" />
        <Setter Property="RowHeight" Value="20" />

        <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="AlternatingRowBackground" Value="{DynamicResource Foreground}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dg:DataGrid}">
                    <ScrollViewer Focusable="false" Name="DG_ScrollViewer">
                        <ScrollViewer.Template>
                            <ControlTemplate TargetType="{x:Type ScrollViewer}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="*"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>

                                    <!--Contour complet de la DataGrid-->
                                    <Border Grid.ColumnSpan="3" Grid.RowSpan="3"
												BorderBrush="{DynamicResource BrushDarkness}" BorderThickness="1,0,1,1" CornerRadius="4,4,4,4" />

                                    <!--Contour des entêtes de colonnes-->
                                    <ContentControl Style="{DynamicResource TitleContentControlStyle}" Grid.ColumnSpan="3" Margin="1,0,1,0"   />

                                    <Button Command="{x:Static dg:DataGrid.SelectAllCommand}" 
                                                Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=RowHeaderActualWidth}"
                                                Focusable="false" OverridesDefaultStyle="True"
                                                Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=HeadersVisibility, Converter={x:Static dg:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static dg:DataGridHeadersVisibility.All}}">
                                        <Button.Template>
                                            <ControlTemplate TargetType="{x:Type Button}">
                                                <Grid>
                                                    <Border Background="{DynamicResource GradientVeryDarkToDarkness}" BorderBrush="{DynamicResource BrushVeryDark}" BorderThickness="0,1">
                                                        <Path x:Name="Arrow" VerticalAlignment="Bottom" Margin="4" Fill="#3000" Width="11" Height="11" Stretch="Fill" Data="M1,0 L1,1 0,1 z"/>
                                                    </Border>
                                                    <Rectangle Width="1" Fill="#AAC377" HorizontalAlignment="Right" />
                                                    <Rectangle Width="1" Margin="0,0,1,0" Fill="#425B10" HorizontalAlignment="Right" />
                                                </Grid>
                                            </ControlTemplate>
                                        </Button.Template>
                                    </Button>
                                    <dg:DataGridColumnHeadersPresenter  Grid.Column="1" Margin="2,0,2,0"                        
                                            Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=HeadersVisibility, Converter={x:Static dg:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static dg:DataGridHeadersVisibility.Column}}" />
                                    <ScrollContentPresenter Grid.Row="1" Grid.ColumnSpan="2" CanContentScroll="{TemplateBinding CanContentScroll}" />
                                    <ScrollBar 
                                            Name="PART_VerticalScrollBar"  Background="{TemplateBinding Background}" Foreground="#FFFFFF" BorderBrush="#FF1D0202"
                                            Grid.Row="1" Grid.Column="2" Orientation="Vertical" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}"
                                            Value="{Binding Path=VerticalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                                    <Grid Grid.Row="2" Grid.Column="1">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=NonFrozenColumnsViewportHorizontalOffset}"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <ScrollBar Grid.Column="1"  Background="{TemplateBinding Background}" Foreground="#FFFFFF" BorderBrush="#FF1D0202"
                                                Name="PART_HorizontalScrollBar" Orientation="Horizontal" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}"
                                                Value="{Binding Path=HorizontalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                                    </Grid>
                                </Grid>
                            </ControlTemplate>
                        </ScrollViewer.Template>
                        <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </ScrollViewer>
                    <!--<Border Background="{TemplateBinding Background}" CornerRadius="4,4,4,4" BorderBrush="{DynamicResource BrushVeryDark}" BorderThickness="2,2,2,2">
                    </Border>-->
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsGrouping" Value="true">
                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>